/*
 * @Author: ShallowInk
 * @Date: 2021-07-26 14:06:33
 * @Description: main 文件
 * @FilePath: \GoodsManagement\src\main.ts
 */
import { createApp, reactive, watch } from "vue";
import App from "./App.vue";
import router from "./router";

const app = createApp(App);

app.use(router);

app.mount("#app");

/**
 * 用路由导航进行对用户的筛选
 */
router.beforeEach((to, from, next) => {  
  //to.name是登录路由的名字
  if (to.name != "Login") {
    //token思路就是登录成功之后保存起来，然后下面拿来用
    let token = localStorage.getItem("key");
    //判断token是否已经保存了
    if (token) {
      //成功跳转
      next();
    } else {
      next("/login");
    }
  } else {
    //不能把所有路由都拦截，要留个登陆路由
    next();
  }
});

/**
 * 提交到缓存中的用户表
 */
localStorage.setItem(
  "userDataSource",
  JSON.stringify([
    {
      userNo: "1",
      name: "admin",
      email: "admin@qq.com",
      phone: "12345678",
      role: "超级管理员",
      password: "123456",
      state: true,
    },
    {
      userNo: "2",
      name: "manager",
      email: "manager@qq.com",
      phone: "12345678",
      role: "管理员",
      password: "123456",
      state: true,
    },
    {
      userNo: "3",
      name: "user1",
      email: "user1@qq.com",
      phone: "12345678",
      role: "用户",
      password: "123456",
      state: true,
    },
    {
      userNo: "4",
      name: "user2",
      email: "user2@qq.com",
      phone: "12345678",
      role: "用户",
      password: "123456",
      state: true,
    },
    {
      userNo: "5",
      name: "user3",
      email: "user3@qq.com",
      phone: "12345678",
      role: "用户",
      password: "123456",
      state: true,
    },
    {
      userNo: "6",
      name: "user4",
      email: "user4@qq.com",
      phone: "12345678",
      role: "用户",
      password: "123456",
      state: true,
    },
    {
      userNo: "7",
      name: "user5",
      email: "user5@qq.com",
      phone: "12345678",
      role: "用户",
      password: "123456",
      state: true,
    },

  ])
);
